# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=udis86
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.7.3rc1
pkgrel=2
pkgdesc="A minimalistic disassembler library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url="https://udis86.sourceforge.io/"
license=("BSD")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
depends=("${MINGW_PACKAGE_PREFIX}-python")
options=('strip' '!libtool' 'staticlibs')
source=(${_realname}::git+https://github.com/vmt/udis86.git#commit=56ff6c87c11de0ffa725b14339004820556e343d
        #"https://downloads.sourceforge.net/udis86/${_realname}-${pkgver}.tar.gz"
        001-pep8-violations.patch
        002-cleanup-and-bug-fixes.patch
        003-python3-fixes.patch
        004-add-cmake-build.patch)
sha256sums=('SKIP'
            '2081a4e4b5d90a1555ddb05632a9e9efc9488a90726250e4cc6ee609a5eaeef7'
            '79eef5840934a3591b09b6de6ad9a411c0313d7c7379cf66978b2181bdd45825'
            'c196636cbe2a34187f89bd239c92ff27eae0b3673f7a557b78335c14a988e3fd'
            '88fb254a94ce28928b04a103e31c1fcba61c87a76c4a4ee09e30d1575bb0e150')

prepare() {
  cd ${_realname}
  patch -p1 -i ${srcdir}/001-pep8-violations.patch
  patch -p1 -i ${srcdir}/002-cleanup-and-bug-fixes.patch
  patch -p1 -i ${srcdir}/003-python3-fixes.patch
  patch -p1 -i ${srcdir}/004-add-cmake-build.patch

  autoreconf -fiv
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST}
  make
}

package () {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install

  cp  ${srcdir}/${_realname}/scripts/*.py ${pkgdir}${MINGW_PREFIX}/bin/
}
